package cn.com.db.service;


import cn.com.db.model.Goods;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GoodsService extends BaseService{

    public void createGoods(Goods goods){
        goodsDao.createGoods(goods);
    }

    public Goods getGoodsById(String id){
        if (StringUtils.isBlank(id)){
            return null;
        }
        return goodsDao.getGoodsById(id);
    }

    public Boolean isExist(String id){
        Goods goods=getGoodsById(id);
        if (goods==null){
            return false;
        }
        if (goods.getDel()){
            return false;
        }
        return goods!=null;
    }

    public Boolean isAlive(String id){
        if(StringUtils.isBlank(id)){
            return false;
        }
        Goods goods=getGoodsById(id);
        if (goods!=null&&!goods.getDel()&&goods.getAlive()){
            return true;
        }
        return false;
    }

    public Integer getGoodsNum(){
        return goodsDao.getGoodsNum();
    }

    public List<Goods> getStoreGoods(String id,Integer page,Integer count){
        return goodsDao.getStoreGoods(id,(page-1)*count,count);
    }

    public Integer countStoreGoods(String id){
        return goodsDao.countStoreGoods(id);
    }


    @Transactional
    public void updateGoods(Goods goods){
        goodsDao.updateGoods(goods);
    }


}
